﻿using Common;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LinkRequest : BaseRequest
{

	LinkPanel linkPanel;
	public override void Start() {
		requestCode = RequestCode.Game;
		actionCode = ActionCode.Link;
		linkPanel = GetComponent<LinkPanel>();
		base.Start();       // 添加记录
	}

	/// <summary>
	/// 发送匹配请求
	/// </summary>
	/// <param name="dif"></param>
	public void RequestLink(int dif) {
		string data = dif.ToString();

		SendRequest(data);
	}


	/// <summary>
	/// 收到响应后开始
	/// </summary>
	/// <param name="data"></param>
	public override void OnResponse(string data) {
		base.OnResponse(data);
		Debug.Log("响应");
		// Debug.Log(data);

		string[] ls = data.Split('|');
		int d0 = int.Parse(ls[0]);
		int d1 = int.Parse(ls[1]);
		Debug.Log(d0);
		Debug.Log(d1);

		if (d0 == linkPanel.dif) {   // 自己的
			gameRoot.ShowGrid2(d1);
		} else {
			gameRoot.ShowGrid2(d0);
		}

		Debug.Log(gameRoot.uiMng);
		gameRoot.uiMng.PopStack();
		gameRoot.uiMng.PushStack(UIPanelType.GamePanel);

		Debug.Log(linkPanel.dif);
		GamePanel gamePanel = gameRoot.uiMng.GetPanel(UIPanelType.GamePanel) as GamePanel;

		Debug.Log(linkPanel.dif);

		gamePanel.CreateGrid(linkPanel.dif);

	}





}
